<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <form action="/login" method="post" enctype="application/x-www-form-urlencoded">
    用户名:<input type="text" name="username" />
    密码：<input type="password" name="password" />
    <!-- <input type="submit" value="登录" /> -->
    <input type="button" id="login" value="登录" />
  </form>
</body>
<script src="./jquery/jquery 3.6.4.js"></script>
<script>
  $("#login").on('click', function () {
    let username = $("[name='username']").val();
    let password = $("[name='password']").val();

    $.ajax({
      url: "/login", type: 'post',
      data: { username, password },
      success(res) {
        console.log(res);
        if (res.code === 200) {
          sessionStorage.token = res.token;
          location.href = '/html/main.html'
        } else {
          alert(res.msg)
        }
      }
    })

  })

</script>

</html>